module Kuztuscms
  class Layout < ActiveRecord::Base
    validates :body, :path, :presence => true
    validates :path, :format => { :with => /\A[a-z0-9_]+\z/, :message => "Only lowercase letters, numbers and dashes allowed"}

    validates :format,  :inclusion => Mime::SET.symbols.map(&:to_s)
    validates :locale,  :inclusion => I18n.available_locales.map(&:to_s)
    validates :handler, :inclusion => ActionView::Template::Handlers.extensions.map(&:to_s)

    class_attribute :prefix

    after_save do
      Kuztuscms::Resolver.instance.clear_cache
    end
  end
end
